<?php
class Gorilla_Pdf_Table {
    public $x;
    public $y;
    public $width;
    public $border = 0.5;
    public $page;
    protected $_pages = array();
    protected $_rows = array();

    function __construct($page, $x, $y) {
        $this->page  = $page;
        $this->x     = $x;
        $this->y     = $y;
    }

    public function addRow(Gorilla_Pdf_Table_Row $row) {
        $this->_rows[] = $row;
    }

    public function render() {
        $y = $this->page->getHeight() - $this->y;
        foreach($this->_rows as $row) {
            if($y - $row->testRender($this->page, $this->x, $y) < 0) {
                $font = $this->page->getFont();
                $font_size = $this->page->getFontSize();
                //$linewidth = $this->page->getLineWidth();
                $this->page = new Gorilla_Pdf_Page($this->page);
                $this->page->setFont($font, $font_size);
                $this->page->setLineWidth($this->border);
                $this->_pages[] = $this->page;
                $y = $this->page->getHeight();
            }
            $row->render($this->page, $this->x, $y);
            $y -= $row->getHeight();
        }
        return $this->_pages;
    }
}
?>
